package com.ideaaedi.springcloud.jd.message.controller;

import com.ideaaedi.springcloud.jd.commonds.entity.message.vo.req.MsgExecLogAddReqVO;
import com.ideaaedi.springcloud.jd.commonds.entity.message.vo.req.MsgExecLogBatchAddReqVO;
import com.ideaaedi.springcloud.jd.commonds.entity.message.vo.req.MsgExecLogListReqVO;
import com.ideaaedi.springcloud.jd.commonds.entity.message.vo.req.MsgExecLogUpdateReqVO;
import com.ideaaedi.springcloud.jd.commonds.entity.message.vo.resp.MsgExecLogBatchAddRespVO;
import com.ideaaedi.springcloud.jd.commonds.entity.message.vo.resp.MsgExecLogDetailRespVO;
import com.ideaaedi.springcloud.jd.commonds.entity.message.vo.resp.MsgExecLogListRespVO;
import com.ideaaedi.springcloud.jd.message.service.MsgExecLogService;
import com.ideaaedi.springcloud.jd.commonds.entity.PageInfo;
import com.ideaaedi.springcloud.jd.commonds.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * 消息-执行日志
 *
 * @author <font size = "20" color = "#3CAA3C"><a href="https://gitee.com/JustryDeng">JustryDeng</a></font> <img src="https://gitee.com/JustryDeng/shared-files/raw/master/JustryDeng/avatar.jpg" />
 * @since 2021.0.5.B
 */
@Validated
@RestController
@RequestMapping("/msg-exec-log")
@Api(value = "消息-执行日志", tags = {"消息-执行日志"})
public class MsgExecLogController {

    @Resource
    private MsgExecLogService msgExecLogService;

    /**
     * 增
     *
     * @param req 参数
     *
     * @return 新增的数据详情
     */
    @ApiOperation("增")
    @PostMapping("/add")
    public Result<MsgExecLogDetailRespVO> add(@RequestBody @Validated MsgExecLogAddReqVO req) {
        return Result.success(msgExecLogService.add(req, true));
    }

    /**
     * 批量增
     *
     * @param req 参数
     *
     * @return MsgExecLogBatchAddRespVO
     */
    @ApiOperation("批量增")
    @PostMapping("/batch-add")
    public Result<MsgExecLogBatchAddRespVO> batchAdd(@RequestBody @Validated MsgExecLogBatchAddReqVO req) {
        return Result.success(msgExecLogService.batchAdd(req));
    }

    /**
     * 删
     *
     * @param id 要删除数据的id
     *
     * @return 删除了的数据详情
     */
    @ApiOperation("删")
    @DeleteMapping("/delete/{id}")
    public Result<MsgExecLogDetailRespVO> delete(@ApiParam(value = "要删除数据的id", required = true)
                                            @PathVariable("id") @NotNull(message = "id cannot be null.") Long id) {
        return Result.success(msgExecLogService.delete(id));
    }

    /**
     * 改
     *
     * @param req 参数
     *
     * @return 修改后的数据详情
     */
    @ApiOperation("改")
    @PutMapping("/update")
    public Result<MsgExecLogDetailRespVO> update(@RequestBody @Validated MsgExecLogUpdateReqVO req) {
        return Result.success(msgExecLogService.update(req));
    }

    /**
     * 查详情
     *
     * @param id 要查询数据的id
     *
     * @return 数据详情
     */
    @ApiOperation("查详情")
    @GetMapping("/detail/{id}")
    public Result<MsgExecLogDetailRespVO> detail(@ApiParam(value = "要查询数据的id", required = true)
                                            @PathVariable("id") @NotNull(message = "id cannot be null.") Long id) {
        return Result.success(msgExecLogService.detail(id));
    }

    /**
     * 查列表
     *
     * @param req 参数
     *
     * @return 数据列表
     */
    @PostMapping("/list")
    @ApiOperation("查列表")
    public Result<PageInfo<MsgExecLogListRespVO>> list(@RequestBody @Validated MsgExecLogListReqVO req) {
        return Result.success(msgExecLogService.list(req));
    }

}
